package com.cn.hangyun.controller;

import java.io.IOException;
import java.util.Date;
import java.util.List;
import java.util.Random;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cn.hangyun.model.Rt_currentspeed_control;
import com.cn.hangyun.model.Rt_currentspeed_transducer;
import com.cn.hangyun.model.Rt_flow_control;
import com.cn.hangyun.model.Rt_flow_transducer;
import com.cn.hangyun.model.Rt_waveheight_control;
import com.cn.hangyun.model.Rt_waveheight_transducer;
import com.cn.hangyun.model.requestVO.SingleTransducerRequestBean;
import com.cn.hangyun.service.IEnvironmentService;

@Controller
@RequestMapping("/environment")
public class EnvironmentController {

	@Autowired
	private IEnvironmentService environmentService;
	
	@RequestMapping("/flowTrans")
	@ResponseBody
	public List<Rt_flow_transducer> getWaveTranas() {
		
		List<Rt_flow_transducer> list = environmentService.getAllFlowTran();
		return list;
	}
	
	@RequestMapping("/waveHightTrans")
	@ResponseBody
	public List<Rt_waveheight_transducer> getWaveHightTranas() {
		
		List<Rt_waveheight_transducer> list = environmentService.getAllWaveTran();
		return list;
	}
	
	
	@RequestMapping("/speedTrans")
	@ResponseBody
	public List<Rt_currentspeed_transducer> getAccTranas() {
		
		List<Rt_currentspeed_transducer> list = environmentService.getAllSpeedTran();
		return list;
	}
	
	/**
	 * 
	 * @param current
	 * @return
	 */
	@RequestMapping("/flowControl")
	@ResponseBody
	public Rt_flow_control getFlowControl(Date current) {
		
		Rt_flow_control result = environmentService.getLastFlowControl(current);
		return result;
	}
	
	/**
	 * 
	 * @param current
	 * @return
	 */
	@RequestMapping("/waveHightControl")
	@ResponseBody
	public Rt_waveheight_control getWaveHightControl(Date current) {
		
		Rt_waveheight_control result = environmentService.getLastWaveControl(current);
		return result;
	}
	
	/**
	 * 
	 * @param current
	 * @return
	 */
	@RequestMapping("/speedControl")
	@ResponseBody
	public Rt_currentspeed_control getSpeedControl(Date current) {
		
		Rt_currentspeed_control result = environmentService.getLastSpeedControl(current);
		return result;
	}
	
	@RequestMapping(value="/speedData",  method=RequestMethod.POST)
	@ResponseBody
	public List<String> getSpeedData(SingleTransducerRequestBean bean) {

		List<String> result = environmentService.getSpeedData(bean);
		return result;
	}
	
	/**
	 * 
	 * @param current
	 * @return
	 */
	@RequestMapping("/waveHightData")
	@ResponseBody
	public List<String> getWaveHightData(SingleTransducerRequestBean bean) {
		
		List<String> result = environmentService.getWaveData(bean);
		return result;
	}
	
	@RequestMapping(value="/flowData",  method=RequestMethod.POST)
	@ResponseBody
	public List<String> getFlowData(SingleTransducerRequestBean bean) {

		List<String> result = environmentService.getFlowData(bean);
		return result;
	}
	
	@RequestMapping(value="/flowAverage",  method=RequestMethod.POST)
	@ResponseBody
	public String getFlowAverage(SingleTransducerRequestBean bean) {

//		FlowAverage result = new FlowAverage();
//		int Num=new Random().nextInt(10)+1;
		
		String result = environmentService.getFlowAverage(bean);
		return result;
	}
	
}



